package com.whcoding.designpatterns.pattern.chainofresponsibility.handler;

import com.whcoding.designpatterns.pattern.chainofresponsibility.vo.UserVO;

/**
 * @program: spring-boot-learning
 * @description: 抽象处理者
 * @author: whcoding
 * @create: 2022-09-19 14:23
 **/
public abstract class LoginHandler<T> {
	protected LoginHandler next;

	private void next(LoginHandler next) {
		this.next = next;
	}

	public abstract void doHandler(UserVO userVO);

	public static class Builder<T> {
		private LoginHandler<T> head;
		private LoginHandler<T> tail;

		public Builder<T> addHandler(LoginHandler handler) {
			if (this.head == null) {
				this.head = this.tail = handler;
				return this;
			}
			this.tail.next(handler);
			this.tail = handler;
			return this;
		}

		public LoginHandler<T> build() {
			return this.head;
		}
	}

}
